package com.lenin.omena.shared.domain;

import java.io.Serializable;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.NotPersistent;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Site implements Serializable, Comparable<Site> {
	
	//private static final long serialVersionUID = 7440297955003302414L;
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY, defaultFetchGroup = "true")
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String key;
	
	@Persistent(mappedBy = "site")
	private User user;
	
	@Persistent(defaultFetchGroup = "true")
	@Element(dependent = "true")
	private List<Produce> produce;
	
	@Persistent
	private Double latitude;
	
	@Persistent
	private Double longitude;
	
	@Persistent(dependent = "true", defaultFetchGroup = "true")
	private Address address;
	
	
	public Site() {
	}
	
	
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Produce> getProduce() {
		return produce;
	}

	public void setProduce(List<Produce> produce) {
		this.produce = produce;
	}
	
	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Double getLatitude() {
		return latitude;
	}
	

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public int compareTo(Site s) {
		return (s == null || s.address == null) ? -1
				: -s.address.compareTo(address);
	}
	
	
	@Override
	public boolean equals(Object o) {
		if (o instanceof Site) {
			return key == ((Site) o).key;
		}
		return false;
	}

}